package Stack::CiscoCatalyst2950;

use strict;

use lib '..';

use Data::Dumper;
use Utils;
use NetAddr::IP;

use Conf; my $conf = Conf->show;

use base qw (Stack);

my $time_before;		# kvoli pocitaniu doby trvania jednotlivych operacii

sub initialize {
	# NEZMAZAT!!! inak bude deep recursion
}

sub get_serial_number {
	my $self = shift;
	return "IMPLEMENT_LATER";
}

sub SNMPgetMAClist {
	my $self = shift;
	my ($vlan_id) = @_;
	return $self->SNMPwalk("mib-2.17.4.3.1.2", $vlan_id);
}

sub MAC2Port {
	my $self = shift;
	my ($MACdec, $vlan_id) = @_;
	return $self->SNMPget("mib-2.17.4.3.1.2.$MACdec", $vlan_id) || 0;
}

sub switch_internal_port_count {
        my $self = shift;
        return 24;
}


sub main_uplink {       # konvencia
        my $self = shift;
        my $unit = 0;
        my $port = 24;
        return ($unit, $port);
}

sub CLI_prompt {
	my $self = shift;
#	return '>';	# prihlasenie do oper modu
	return '#';	# prihlasenie do enable modu
}

sub CLI_configure {
	my $self = shift;
	my ($commands) = @_;
	return $self->cmd("end\nconfigure terminal\n$commands\nend\n");
}

sub CLI_quit {
	my $self = shift;
	return "end\nexit\n";
}

sub CLI_saveconfig {
	my $self = shift;
	my $config_name = $self->standard_conf_filename;
	return "end\ncopy running-config startup-config\n$config_name\n";
}

sub translatePortNumber {	#	portnum => unit, port
        my $self = shift;
	return (0, shift);	# nestohovatelne Cisco - unit je v tomto pripade vzdy 0 a portnum = port (rozdiel napr. oproti SMC, kde je tato funkcia zlozitejsia)
}

sub detranslatePortNumber {	#	unit, port => portnum
        my $self = shift;
        my ($unit,$port) = @_;
        return $port;		# analogicky ako v pripade translatePortNumber()
}
# metody nastavujuce ACL budu implementovane neskor
sub extended_IPACL_name {
# TODO: implementovat metodu
}
sub unbind_extended_IPACL {
# TODO: implementovat metodu
}
sub drop_extended_IPACL {
# TODO: implementovat metodu
}
sub enter_extended_IPACL_rules {
# TODO: implementovat metodu
}
sub IPACL_deny_dhcp_server {
# TODO: implementovat metodu
}

# deprecated, metodu odstranit - stala sa sucastou IPACL_deny_default()
#sub IPACL_permit_dhcp_client {
# TODO: implementovat metodu
#}

sub IPACL_permit_destinations {
# TODO: implementovat metodu
}
sub IPACL_permit_sources {
# TODO: implementovat metodu
}
sub IPACL_deny_default {
# TODO: implementovat metodu
}
sub bind_extended_IPACL {
# TODO: implementovat metodu
}

# tato je deprecated, odstranit
#sub set_switchport_broadcast_max_packet_rate {
# TODO: implementovat metodu
#}

# deprecated, nastavuje sa rucne (zatial)
#sub set_switchport_broadcast_max_bitrate {
#}

sub set_switchport_description {
        my $self = shift;
        my ($unit, $port, $description) = @_;
        return $self->CLI_configure_interface($unit,$port,"description $description\n");
}
sub set_switchport_access_VLAN {
# TODO: implementovat metodu
}
sub CLI_show {
        my $self = shift;
        my ($what) = @_;
        return $self->cmd("show $what\n")
}

sub backupStartupConfig {
	my $self = shift;
	my $dstfile = $self->standard_conf_filename;
	my $tftp_ip=$conf->{TFTP_IP};
	$self->cmd("copy startup-config tftp:\n$tftp_ip\n$dstfile");
}

sub backupRunningConfig {
	my $self = shift;
	my $dstfile = $self->standard_conf_filename."_running";
	my $tftp_ip=$conf->{TFTP_IP};
	$self->cmd("copy running-config tftp:\n$tftp_ip\n$dstfile");
}

sub set_static_addr_uplink {	# nastavi na zvolenej VLAN hlavneho uplinku staticku MAC (typicky default gw)
# TODO: implementovat metodu
}

sub set_port_max_MAC_count {
}

# tiez doriesit neskor
sub CLI_set_RADIUS {	# nastavi RADIUS secret key a max. 5 RADIUS serverov
#	my $self = shift;
#	my ($key, $host1, $host2, $host3, $host4, $host5) = @_;
#	return "radius-server key $key\nno radius-server 1\nradius-server 1 host $host1\nno radius-server 2\
#	radius-server 2 host $host2\no radius-server 3\nradius-server 3 host $host3\
#	no radius-server 4\nradius-server 4 host $host4\nno radius-server 5\nradius-server 5 host $host5\n";
}

# nastavenie GVRP zatial neimplementovane
sub CLI_set_GVRP {	# nastavi/odstavi globalne GVRP
# TODO: implementovat metodu
}

# neskor sa doimplementuje
sub CLI_set_SNTP {	# nastavi synchronizaciu hodin s casovymi servermi
# TODO: implementovat metodu
}


sub CLI_set_ident {	# nastavi na zariadeni hostname, CLI prompt, location a kontakt na admina
	my $self = shift;
	my ($hostname, $location, $admin_email) = @_;
	return "hostname $hostname\nsnmp-server location $location\nsnmp-server contact $admin_email\n";
}

sub CLI_set_SNMPcommunity {	# nastavi rw/ro community string alebo ho odstavi
	my $self = shift;
	my ($string, $type) = @_;
	if ($type) {
		if ($type == 7) {	# 7 = read-write community string
			return "snmp-server community $string rw\n";
		} else {		# readonly community string
			return "snmp-server community $string ro\n";
		}
	} else {			# delete community string
		return "no snmp-server community $string\n";
	}
}

sub CLI_set_syslog {
	my $self = shift;
	my ($host, $off) = @_;
	if ($off) {
		return "no logging $host\n";
	} else {
		return "logging $host\n";
	}
}

# doimplementovat neskor
sub CLI_set_logging {
# TODO: implementovat metodu
}

sub CLI_set_STP {
	my $self = shift;
	my ($mode) = @_;
	return "spanning-tree mode $mode\n";
}

sub CLI_configure_interface {
	my $self = shift;
	my ($unit, $port, $commands) = @_;
	return $self->CLI_configure("interface fastEthernet $unit/$port\n$commands\n");
}

1;

